import Vue from 'vue'
import Vuex from 'vuex'
import getters from './getters'

Vue.use(Vuex)

const storeModules = require.context('./modules', true, /\.js/)
const reg = new RegExp(/^\.\/(.*)\.\w+$/);
const modules = storeModules.keys().reduce((result, path) => {
    const value = storeModules(path)
    const name = path.replace(reg, '$1')
    if (value) {
        result[name] = value.default
    }
    return result
}, {})

const store = new Vuex.Store({
    modules,
    getters
})

export default store
